{extend name="common/block" /}

{block name="content"}
<div class="container-fluid">
    {if $data.is_default_password}
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">
                    您还在使用初始密码请<a href="userinfo">修改密码</a>
                </div>
            </div>
        </div>
    </div>
    {/if}

    <div class="row">
        <div class="col-lg-12">
            <div class="col-sm-6 col-lg-2">
                <div class="card bg-danger">
                    <div class="card-body clearfix">
                        <div class="pull-right">
                            <p class="h6 text-white m-t-0">链接总数</p>
                            <p class="h3 text-white m-b-0 fa-1-5x">{$data.all_num}</p>
                        </div>
                        <div class="pull-left"><span class="img-avatar img-avatar-48 bg-translucent"><i
                                class="mdi mdi-link fa-1-5x"></i></span></div>
                    </div>
                </div>
            </div>

            <div class="col-sm-6 col-lg-2">
                <div class="card bg-warning">
                    <div class="card-body clearfix">
                        <div class="pull-right">
                            <p class="h6 text-white m-t-0">今日生成</p>
                            <p class="h3 text-white m-b-0 fa-1-5x">{$data.today_set_num}</p>
                        </div>
                        <div class="pull-left"><span class="img-avatar img-avatar-48 bg-translucent"><i
                                class="mdi mdi-link-variant fa-1-5x"></i></span></div>
                    </div>
                </div>
            </div>

            <div class="col-sm-6 col-lg-2">
                <div class="card bg-success">
                    <div class="card-body clearfix">
                        <div class="pull-right">
                            <p class="h6 text-white m-t-0">总访问量</p>
                            <p class="h3 text-white m-b-0 fa-1-5x">{$data.all_visit}</p>
                        </div>
                        <div class="pull-left"><span class="img-avatar img-avatar-48 bg-translucent"><i
                                class="mdi mdi-comment-outline fa-1-5x"></i></span></div>
                    </div>
                </div>
            </div>

            <div class="col-sm-6 col-lg-2">
                <div class="card bg-info">
                    <div class="card-body clearfix">
                        <div class="pull-right">
                            <p class="h6 text-white m-t-0">今日总访问量</p>
                            <p class="h3 text-white m-b-0 fa-1-5x">{$data.all_today_visit}</p>
                        </div>
                        <div class="pull-left"><span class="img-avatar img-avatar-48 bg-translucent"><i
                                class="mdi mdi-comment-outline fa-1-5x"></i></span></div>
                    </div>
                </div>
            </div>

            <div class="col-sm-6 col-lg-2">
                <div class="card bg-purple">
                    <div class="card-body clearfix">
                        <div class="pull-right">
                            <p class="h6 text-white m-t-0">账户余额</p>
                            <p class="h3 text-white m-b-0 fa-1-5x">{$data.user.money}</p>
                        </div>
                        <div class="pull-left"><span class="img-avatar img-avatar-48 bg-translucent"><i
                                class="mdi mdi-currency-cny  fa-1-5x"></i></span></div>
                    </div>
                </div>
            </div>

            <div class="col-sm-6 col-lg-2">
                <div class="card bg-pink">
                    <div class="card-body clearfix">
                        <div class="pull-right">
                            <p class="h6 text-white m-t-0">账户状态</p>
                            <p class="h3 text-white m-b-0 fa-1-5x">{if $data.user.status == 1}正常{else /}禁用{/if}</p>
                        </div>
                        <div class="pull-left"><span class="img-avatar img-avatar-48 bg-translucent"><i
                                class="mdi mdi-comment-outline fa-1-5x"></i></span></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">开发信息</div>
                <div class="card-body">
                    <form action="#!" class="form-horizontal">
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="appid">appid</label>
                            <div class="col-md-7">
                                <div class="input-group">
                                    <input class="form-control" type="text" id="appid" value="{$data.user.appid}"
                                           readonly>
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-dark" onclick="copyToClip(this)">复制
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="secret">secret</label>
                            <div class="col-md-7">
                                <div class="input-group">
                                    <input class="form-control" type="text" id="secret" value="{$data.user.secret}"
                                           readonly>
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-dark" onclick="copyToClip(this)">复制
                                        </button>
                                        <button type="button" class="btn btn-success" onclick="resetSecret()">重置
                                        </button>
                                    </div>
                                </div>
                                <div class="tips">7天内只能重置一次</div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-3 control-label" for="ip">ip白名单</label>
                            <div class="col-md-7">
                                <textarea class="form-control" name="ip" id="ip" cols="30" rows="10">{$data.user.ip_list}</textarea>
                                <div class="tips">每行一个</div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label"></label>
                            <div class="col-md-7">
                                <button class="btn btn-primary" type="button" onclick="saveIpList()">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

</div>
{/block}


{block name="jsLogic"}
<script type="text/javascript" src="/static/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/static/js/lightyear.js"></script>
<script type="text/javascript" src="/static/js/main.min.js"></script>
<script>
    function resetSecret() {
        $.ajax({
            url: 'resetSecret',
            method: 'post',
            data: {
                time: new Date().toLocaleString()
            },
            success: function (res) {
                if (res.code == 200) {
                    $('#secret').value(res.data.secret);
                } else {
                    lightyear.notify(res.message, 'warning', 1000, '', 'top', 'center')
                }
            },
            error: function (res) {
                lightyear.notify('网络异常', 'danger', 1000, '', 'top', 'center')
            }
        });
    }

    function copyToClip(e) {
        var content = $(e).parent('div').prev('input').val();
        var aux = document.createElement("input");
        aux.setAttribute("value", content);
        document.body.appendChild(aux);
        aux.select();
        document.execCommand("copy");
        document.body.removeChild(aux);
        lightyear.notify('内容已复制到剪切板', 'success', 1000, '', 'top', 'center')
    }

    function saveIpList() {
        var ipList = $('textarea').val();

        $.ajax({
            url: 'changeiplist',
            method: 'post',
            data: {
                ip: ipList
            },
            success: function (res) {
                if (res.code == 200) {
                    lightyear.notify(res.message);
                } else {
                    lightyear.notify(res.message, 'warning', 1000, '', 'top', 'center')
                }
            },
            error: function (res) {
                lightyear.notify('网络异常', 'danger', 1000, '', 'top', 'center')
            }
        })
    }
</script>
{/block}
